//
//  RoomCollectionViewCell.m
//  fp
//
//  Created by xingshuai on 2020/11/10.
//

#import "RoomCollectionViewCell.h"

@interface RoomCollectionViewCell ()

@property (nonatomic, strong) UIImageView *playerView;  // 缩略图
@property (nonatomic, strong) UIImageView *backImg;     // 背景图
@property (nonatomic, strong) UILabel *timeLabel;       // 时间
@property (nonatomic, strong) UILabel *titleLabel;      // 标题
@property (nonatomic, strong) UILabel *detiLabel;       // 描述
@property (nonatomic, strong) UIImageView *playImg;     // 播放图片
@property (nonatomic, strong) UIProgressView *progressView; // 学习进度
@property (strong, nonatomic) UIImageView *checkImageView;  // 编辑状态按钮

@end

@implementation RoomCollectionViewCell

-(instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        //得到view的遮罩路径
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.contentView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(16,16)];
        //创建 layer
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = self.contentView.bounds;
        //赋值
        maskLayer.path = maskPath.CGPath;
        self.contentView.layer.mask = maskLayer;
        
        self.backImg = [[UIImageView alloc]init];
        self.backImg.image = [UIImage imageNamed:@"play_back"];
        [self.contentView addSubview:self.backImg];
        [self.backImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.contentView);
        }];
        
        self.playerView = [[UIImageView alloc]init];
        self.clipsToBounds = YES;
        self.playerView.image = [UIImage imageNamed:@"def_img-1"];
        self.playerView.contentMode = UIViewContentModeScaleAspectFill;
        [self.contentView addSubview:self.playerView];
        [self.playerView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.right.equalTo(self.contentView);
            //make.bottom.equalTo(self.contentView.mas_bottom).offset(-68);
            make.height.mas_offset(self.contentView.bounds.size.height/3*2);
        }];
        
        self.timeLabel = [[UILabel alloc]init];
        self.timeLabel.text = @"00:00";
        self.timeLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:12];
        self.timeLabel.textAlignment = NSTextAlignmentCenter;
        self.timeLabel.textColor = [UIColor colorWithHexString:@"#FFFFFF"];
        self.timeLabel.backgroundColor = [UIColor colorWithHexString:@"#000000" alpha:0.5];
        [self.playerView addSubview:self.timeLabel];
        [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.right.equalTo(self.playerView).offset(-5);
            make.size.mas_offset(CGSizeMake(50, 25));
        }];
        
        
        self.playImg = [[UIImageView alloc]init];
        self.playImg.image = [UIImage imageNamed:@"play_img"];
        self.playImg.contentMode = UIViewContentModeScaleAspectFill;
        [self.contentView addSubview:self.playImg];
        [self.playImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).offset(-10);
            make.bottom.equalTo(self.contentView).offset(-((self.contentView.bounds.size.height/3-XS_FONT(30))/2));
            make.size.mas_offset(CGSizeMake(XS_FONT(30), XS_FONT(30)));
        }];
        
        // 辅助适配
        UILabel *line = [[UILabel alloc]init];
        line.backgroundColor = [UIColor clearColor];
        [self.contentView addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.playImg);
            make.left.right.equalTo(self.contentView);
            make.height.mas_offset(1);
        }];
        
        self.titleLabel = [[UILabel alloc]init];
        self.titleLabel.text = @"拼音、汉字全面梳理讲";
        self.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:16];
        self.titleLabel.textColor = [UIColor colorWithHexString:@"#3B3B3B"];
        [self.contentView addSubview:self.titleLabel];
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(7);
            make.bottom.equalTo(line.mas_top);
            make.right.equalTo(self.playImg.mas_left).offset(-5);
        }];
        
        self.detiLabel = [[UILabel alloc]init];
        self.detiLabel.text = @"小学分类-认识周围";
        self.detiLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:14];
        self.detiLabel.textColor = [UIColor colorWithHexString:@"#92979C"];
        [self.contentView addSubview:self.detiLabel];
        [self.detiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(7);
            make.top.equalTo(line.mas_bottom);
            make.right.equalTo(self.playImg.mas_left).offset(-5);
        }];
        
        _progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
        _progressView.trackTintColor = [UIColor colorWithHexString:@"#CBCBCB"];
        _progressView.progressTintColor = [UIColor colorWithHexString:@"#4E75FF"];
        _progressView.progress = 0.6;
        _progressView.hidden = YES;
        [self.contentView addSubview:self.progressView];
        [self.progressView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.contentView);
            make.bottom.equalTo(self.playerView.mas_bottom);
            make.height.mas_offset(3);
        }];
        
        self.checkImageView = [[UIImageView alloc] init];
        self.checkImageView.image = [UIImage imageNamed:@"edit_n"];
        [self.contentView addSubview:self.checkImageView];
        self.checkImageView.hidden = YES;
        [self.checkImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_offset(CGSizeMake(26, 26));
            make.left.top.equalTo(self.contentView).offset(10);
        }];
    }
    return self;
}

-(void)setModel:(XSUserRoomModel *)model {
    if (model.isEdit) {
        self.checkImageView.hidden = NO;
        if (model.isSelect) {
            self.checkImageView.image = [UIImage imageNamed:@"edit_s"];
        } else {
            self.checkImageView.image = [UIImage imageNamed:@"edit_n"];
        }
    } else {
        self.checkImageView.hidden = YES;
    }
}


-(void)setIsHidenPro:(BOOL)isHidenPro {
    self.progressView.hidden = isHidenPro;
}

@end
